package cn.java.exercises;

public class SortFind
{
    public static void main(String[] args)
    {
        int nScores[]={ 365,401,406,455,389,378,376,303,289,405,
                465,411,306,459,479,388,346,335,299,415,
                485,403,407,469,471,438,396,345,369,408,
                395,409,417,429,478,428,394,426,466,418,
                393,463,429,464,441,458,386,395,348,447
        };
        int nRanks[]={ 1,2,3,4,5,6,7,8,9,10,
                11,12,13,14,15,16,17,18,19,20,
                21,22,23,24,25,26,27,28,29,30,
                31,32,33,34,35,36,37,38,39,40,
                41,42,43,44,45,46,47,48,49,50
        };
        String sNames[]={"陈奕","何春容","李琪霞","陈珍珍","虞喆斯","张颖","赵超群","吴丽萍","潘丹琴","巫梦婷",
                "余梢婷","余丽君","胡梦诗","范玲娇","丰凯怡","张红梅","虞鑫悦","周佳慧","连青坡","沙孟",
                "张道阳","陈宇航","陈瀚犇","陈明星","庄凌","胡清扬","劳一鸣","林总涛","陈斌","方开渊",
                "胡斌","金阿青","马杰","董滨杰","马圆涛","姚仕纲","朱鸿扬","胡康鹏","崔俊杰","沃雪野",
                "祝俊儿","张宏鑫","丁玲钰","彭嘉慧","毛利燕","周烯烯","吴霞芸","郑洁儿","徐书晴","杨丽珍"
        };

        int nValue=0,k=0,nRanking=0;
        for (int i = 1; i < 50; i++)
        {
            nValue=nScores[i];
            nRanking=nRanks[i];
            for (int j = 0; j < i; j++)
            {
                if(nValue > nScores[j])
                {
                    k=i;
                    while (k>j)
                    {
                        nScores[k]=nScores[k-1];
                        nRanks[k]=nRanks[k-1];
                        k--;
                    }
                    nScores[j]=nValue;
                    nRanks[j]=nRanking;
                    break;
                }
            }
        }

//        for (int i = 0; i < 50; i++)
//        {
//            System.out.println("名次:"+(i+1)+"    学号:"+nRanks[i]+"    姓名:"+sNames[nRanks[i]-1]+"    分数:"+nScores[i]);
//        }

        nValue=365;
        int nLow=0,nHigh=49,nMid;

        while (nLow <= nHigh)
        {
            nMid=(nLow+nHigh)/2;
            if(nValue > nScores[nMid])
            {
                nHigh=nMid-1;
            }
            else if(nValue < nScores[nMid])
            {
                nLow=nMid+1;
            }
            else
            {
                System.out.println("名次:"+(nMid+1)+"    学号:"+nRanks[nMid]+"    姓名:"+sNames[nRanks[nMid]-1]+"    分数:"+nScores[nMid]);
                break;
            }
        }

    }
}
